﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="CcsSparseClearableMatrixOperationsProvider.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential
{
    #region Usings

    using System;

    using ExulLibrary.Exceptions;

    #endregion

    /// <summary>
    ///     Provides operations for <see cref="CcsSparseMatrix{T}"/> through interface.
    /// </summary>
    internal sealed class CcsSparseClearableMatrixOperationsProvider : IClearableMatrixOperationsProvider
    {
        #region Implemented Interfaces

        #region IClearableMatrixOperationsProvider

        /// <summary>
        ///     Sets the default value to all elements of the matrix.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of values of matrix elements.
        /// </typeparam>
        /// <param name="matrix">
        ///     The matrix that contains elements to clear.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="matrix"/> is <see langword="null"/>.
        /// </exception>
        public void Clear<T>(Matrix<T> matrix)
        {
            var realMatrix = matrix as CcsSparseMatrix<T>;
            realMatrix.Clear();
        }

        /// <summary>
        ///     Sets the default value to all elements in the specified column of the matrix.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of values of matrix elements.
        /// </typeparam>
        /// <param name="matrix">
        ///     The matrix that contains the column to clear.
        /// </param>
        /// <param name="columnIndex">
        ///     The zero-based index of the column to clear.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="matrix"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ElementIndexIsOutOfRangeException">
        ///     <paramref name="columnIndex"/> is negative or greater than or equal to columns count.
        /// </exception>
        public void ClearColumn<T>(Matrix<T> matrix, int columnIndex)
        {
            var realMatrix = matrix as CcsSparseMatrix<T>;
            realMatrix.ClearColumn(columnIndex);
        }

        /// <summary>
        ///     Sets the default value to all elements in the specified row of the matrix.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of values of matrix elements.
        /// </typeparam>
        /// <param name="matrix">
        ///     The matrix that contains the row to clear.
        /// </param>
        /// <param name="rowIndex">
        ///     The zero-based index of the row to clear.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="matrix"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ElementIndexIsOutOfRangeException">
        ///     <paramref name="rowIndex"/> is negative or greater than or equal to rows count.
        /// </exception>
        public void ClearRow<T>(Matrix<T> matrix, int rowIndex)
        {
            var realMatrix = matrix as CcsSparseMatrix<T>;
            realMatrix.ClearRow(rowIndex);
        }

        #endregion

        #endregion
    }
}